// 波纹
Shader "Study/Chapter3/DrawWave"
{
    Properties
    {
        _Color("Color",Color) = (1,1,1,1)
		_Amplitude("Amplitude",Range(0,0.1)) = 0.03   // 振幅
		_Frequency("Frequency",Range(0,20)) = 8   // 频率(振频)
		_Height("Height",Range(0,1)) = 0.4        

    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

			float4 _Color;
			float _Amplitude;
			float _Frequency;
			float _Height;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
				fixed s = i.uv.y + sin((i.uv.x + _Time.y) * _Frequency) * _Amplitude;
				fixed val = step(s,_Height);
				return val * _Color;
            }
            ENDCG
        }
    }
}
